package com.gpframework.module.controller.wages;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.common.utils.poi.ExcelUtil;
import com.gpframework.module.wages.domain.GzTotalSalesOfTheCompany;
import com.gpframework.module.wages.domain.req.GzTotalSalesOfTheCompanyAdd;
import com.gpframework.module.wages.domain.req.GzTotalSalesOfTheCompanyReq;
import com.gpframework.module.wages.domain.req.GzTotalSalesOfTheCompanyUpdate;
import com.gpframework.module.wages.domain.vo.GzTotalSalesOfTheCompanyVo;
import com.gpframework.module.wages.service.IGzPersonnelFoundationService;
import com.gpframework.module.wages.service.IGzTotalSalesItemsService;
import com.gpframework.module.wages.service.IGzTotalSalesOfTheCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
/**
 * @ClassName GzTotalSalesOfTheCompanyController
 * @Author gpframework
 * @Date 2024-01-19
 * @Version 1.0.0
 * @Description 公司总销售Controller
 */
@Validated
@Api(tags = "公司总销售")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/wages/totalsalesofthecompany" )
public class GzTotalSalesOfTheCompanyController extends BaseController {

    private final IGzTotalSalesOfTheCompanyService iGzTotalSalesOfTheCompanyService;

    private final IGzTotalSalesItemsService iGzTotalSalesItemsService;
    private final IGzPersonnelFoundationService iGzPersonnelFoundationService;

    /**
     * @Description 分页
     * @Author gpframework
     * @Date 2024-01-19
     * @Param gzTotalSalesOfTheCompany
     * @Return TableDataInfo
     */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('wages:totalsalesofthecompany:list')")
    @GetMapping("/list")
    public TableDataInfo<GzTotalSalesOfTheCompanyVo> list(GzTotalSalesOfTheCompanyReq gzTotalSalesOfTheCompanyReq) {
        startPage();
        QueryWrapper<GzTotalSalesOfTheCompany> lqw = new QueryWrapper<GzTotalSalesOfTheCompany>();
        gzTotalSalesOfTheCompanyReq.generatorQuery(lqw, true);
        List<GzTotalSalesOfTheCompanyVo> list = iGzTotalSalesOfTheCompanyService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2024-01-19
     * @Param gzTotalSalesOfTheCompany
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('wages:totalsalesofthecompany:add')")
    @Log(title = "添加公司总销售", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GzTotalSalesOfTheCompanyAdd gzTotalSalesOfTheCompanyAdd) {

        return toAjax(iGzTotalSalesOfTheCompanyService.addTotalSalesOfTheCompany(gzTotalSalesOfTheCompanyAdd) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2024-01-19
     * @Param gzTotalSalesOfTheCompany
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('wages:totalsalesofthecompany:edit')")
    @Log(title = "修改公司总销售", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GzTotalSalesOfTheCompanyUpdate gzTotalSalesOfTheCompanyUpdate){
        GzTotalSalesOfTheCompany gzTotalSalesOfTheCompany = Convert.convert(new TypeReference<GzTotalSalesOfTheCompany>() {
        }, gzTotalSalesOfTheCompanyUpdate);
        return toAjax(iGzTotalSalesOfTheCompanyService.updateById(gzTotalSalesOfTheCompany) ? 1 : 0);
    }


        /**
         * @Description 导出
         * @Author gpframework
         * @Date 2024-01-19
         * @Param gzTotalSalesOfTheCompany
         * @Return TableDataInfo
         */

        @PreAuthorize("@ss.hasPermi('wages:totalsalesofthecompany:export')")
        @Log(title = "导出公司总销售", businessType = BusinessType.EXPORT)
        @GetMapping("/export")
        public AjaxResult export (GzTotalSalesOfTheCompanyReq gzTotalSalesOfTheCompanyReq){
            QueryWrapper<GzTotalSalesOfTheCompany> lqw = new QueryWrapper<GzTotalSalesOfTheCompany>();
            gzTotalSalesOfTheCompanyReq.generatorQuery(lqw, true);
            List<GzTotalSalesOfTheCompanyVo> list = iGzTotalSalesOfTheCompanyService.listVo(lqw);
            ExcelUtil<GzTotalSalesOfTheCompanyVo> util = new ExcelUtil<GzTotalSalesOfTheCompanyVo>(GzTotalSalesOfTheCompanyVo.class);
            return util.exportExcel(list, "totalsalesofthecompany");
        }

        /**
         * @Description 详情
         * @Author gpframework
         * @Date 2024-01-19
         * @Param gzTotalSalesOfTheCompany
         * @Return TableDataInfo
         */
        @ApiOperation("详情")
        @PreAuthorize("@ss.hasPermi('wages:totalsalesofthecompany:query')")
        @GetMapping(value = "/{id}")
        public AjaxResult<GzTotalSalesOfTheCompanyVo> getInfo (@PathVariable("id") Long id){
            return AjaxResult.success(iGzTotalSalesOfTheCompanyService.getVoById(id));
        }


        /**
         * @Description 删除
         * @Author gpframework
         * @Date 2024-01-19
         * @Param gzTotalSalesOfTheCompany
         * @Return TableDataInfo
         */
        @ApiOperation("删除")
        @PreAuthorize("@ss.hasPermi('wages:totalsalesofthecompany:remove')")
        @Log(title = "删除公司总销售", businessType = BusinessType.DELETE)
        @DeleteMapping("/{ids}")
        public AjaxResult remove (@PathVariable Long[]ids){
            return toAjax(iGzTotalSalesOfTheCompanyService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
        }
    }

